package com.talent.service.iot.mqtt.model.response;

import com.talent.service.iot.mqtt.model.entity.TlTopic;
import com.talent.service.iot.mqtt.model.fix.TlMqttFixedHead;
import com.talent.service.iot.mqtt.model.payload.TlMqttSubAckPayload;
import com.talent.service.iot.mqtt.model.variable.TlMqttSubAckVariableHead;
import io.netty.handler.codec.mqtt.MqttMessageType;

import java.util.List;

/**
 * @ClassName：TlMqttConnackRes
 * @Author: hszhou
 * @Date: 2024/11/25 11:12
 * @Description: 订阅响应
 */
public class TlMqttSubAck {


    private TlMqttFixedHead fixedHead;
    private TlMqttSubAckVariableHead variableHead;

    private TlMqttSubAckPayload payload;

    public TlMqttFixedHead getFixedHead() {
        return fixedHead;
    }

    public void setFixedHead(TlMqttFixedHead fixedHead) {
        this.fixedHead = fixedHead;
    }

    public TlMqttSubAckVariableHead getVariableHead() {
        return variableHead;
    }

    public void setVariableHead(TlMqttSubAckVariableHead variableHead) {
        this.variableHead = variableHead;
    }

    public TlMqttSubAckPayload getPayload() {
        return payload;
    }

    public void setPayload(TlMqttSubAckPayload payload) {
        this.payload = payload;
    }

    public TlMqttSubAck(TlMqttFixedHead fixedHead, TlMqttSubAckVariableHead variableHead, TlMqttSubAckPayload payload) {
        this.fixedHead = fixedHead;
        this.variableHead = variableHead;
        this.payload = payload;
    }

    public static TlMqttSubAck of(List<TlTopic> topics, int messageId){

        TlMqttFixedHead fixedHead = TlMqttFixedHead.of(MqttMessageType.SUBACK);

        TlMqttSubAckVariableHead variableHead = TlMqttSubAckVariableHead.of(messageId);



        TlMqttSubAckPayload payload = TlMqttSubAckPayload.of(topics);

        return new TlMqttSubAck(fixedHead,variableHead,payload);

    }
}
